#import "TJPickerView.h"
@interface TJPickerView()<UIPickerViewDelegate>
@end
@implementation TJPickerView
- (void)dismissPicker {
    [self dismiss];
}
- (instancetype)initWithTitle:(NSString *)title pickerMode:(BRDatePickerMode)pickerModel minDate:(NSDate *)minDate completion:(ConfirmBlock)pickerDidComfirm {
    return [self initWithTitle:title pickerMode:pickerModel minDate:minDate maxDate:[NSDate dateWithTimeIntervalSinceNow:86400*90] completion:pickerDidComfirm];
}
-(instancetype)initWithTitle:(NSString *)title pickerMode:(BRDatePickerMode)pickerModel minDate:(NSDate *)minDate maxDate:(NSDate *)maxDate completion:(ConfirmBlock)pickerDidComfirm {
    if (self = [super init]) {
        self.pickerMode = pickerModel;
        self.title = title;
        self.selectDate = [NSDate dateWithString:@"01/01/1992" format:@"dd/MM/yyyy"];
        self.minDate = minDate;
        self.maxDate = maxDate;
        self.isAutoSelect = YES;
        self.resultBlock = ^(NSDate *selectDate, NSString *selectValue) {
            if (pickerDidComfirm) {
                pickerDidComfirm(selectDate,selectValue);
            }
        };
        BRPickerStyle *customStyle = [[BRPickerStyle alloc] init];
        customStyle.pickerColor = [UIColor whiteColor];
        customStyle.titleBarColor = [UIColor whiteColor];
        customStyle.pickerTextColor = [UIColor blackColor];
        customStyle.separatorColor = [UIColor color333];
        customStyle.titleTextColor = [UIColor blackColor];
        customStyle.titleTextFont = [UIFont boldSystemFontOfSize:Ratio(16)];
        customStyle.cancelTextColor = [UIColor colorWithHexString:@"#8E93A1"];
        customStyle.doneTextColor = [UIColor colorFF6C2E];
        customStyle.selectRowTextFont = [UIFont boldSystemFontOfSize:Ratio(16)];
        customStyle.rowHeight = Ratio(58);
        customStyle.cancelBtnTitle = @"Cancle";
        customStyle.doneBtnTitle = @"OK";
        customStyle.hiddenTitleLine = YES;
        customStyle.pickerHeight = Ratio(232);
        self.pickerStyle = customStyle;
    }
    return self;
}
+(id)showAtBottomWithTitle:(NSString *)title pickerMode:(BRDatePickerMode)pickerModel minDate:(NSDate *)minDate completion:(ConfirmBlock)pickerDidComfirm {
    BRDatePickerView *datePickerView = [self showAtBottomWithTitle:title pickerMode:pickerModel minDate:minDate maxDate:[NSDate dateWithTimeIntervalSinceNow:86400*90] completion:pickerDidComfirm];
    return datePickerView;
}
+(id)showAtBottomWithTitle:(NSString *)title pickerMode:(BRDatePickerMode)pickerModel minDate:(NSDate *)minDate maxDate:(NSDate *)maxDate completion:(ConfirmBlock)pickerDidComfirm {
    BRDatePickerView *datePickerView = [[BRDatePickerView alloc] init];
    datePickerView.pickerMode = pickerModel;
    datePickerView.title = title;
    datePickerView.selectDate = [NSDate date];
    datePickerView.minDate = minDate;
    datePickerView.maxDate = maxDate;
    datePickerView.isAutoSelect = YES;
    datePickerView.resultBlock = ^(NSDate *selectDate, NSString *selectValue) {
        if (pickerDidComfirm) {
            pickerDidComfirm(selectDate,selectValue);
        }
    };
    datePickerView.pickerStyle = [self customStyle];
    [datePickerView show];
    return datePickerView;
}
+ (void)showStringPickerWithTitle:(NSString *)title dataSources:(NSArray <NSString *>*)dataSources selectValue:(NSString *)selectValue completion:(void (^)(NSString *select))completion {
    BRStringPickerView *stringPicker = [[BRStringPickerView alloc] initWithPickerMode:BRStringPickerComponentSingle];
    stringPicker.title = title;
    stringPicker.dataSourceArr = dataSources;
    stringPicker.selectValue = selectValue;
    stringPicker.isAutoSelect = YES;
    stringPicker.resultModelBlock = ^(BRResultModel * _Nullable resultModel) {
        completion(resultModel.value);
    };
    stringPicker.pickerStyle = [self customStyle];
    [stringPicker show];
}
+ (BRPickerStyle *)customStyle {
    BRPickerStyle *customStyle = [[BRPickerStyle alloc] init];
    customStyle.pickerColor = [UIColor whiteColor];
    customStyle.titleBarColor = [UIColor whiteColor];
    customStyle.pickerTextColor = [UIColor blackColor];
    customStyle.separatorColor = [UIColor color333];
    customStyle.titleTextColor = [UIColor blackColor];
    customStyle.titleTextFont = [UIFont boldSystemFontOfSize:Ratio(16)];
    customStyle.cancelTextColor = [UIColor colorWithHexString:@"#8E93A1"];
    customStyle.doneTextColor = [UIColor colorFF6C2E];
    customStyle.selectRowTextFont = [UIFont boldSystemFontOfSize:Ratio(16)];
    customStyle.rowHeight = Ratio(58);
    customStyle.cancelBtnTitle = @"Cancle";
    customStyle.doneBtnTitle = @"OK";
    customStyle.hiddenTitleLine = YES;
    customStyle.pickerHeight = Ratio(232);
    return customStyle;
}
@end
